#define pTTCC1P1Pi_cxx
#include "pTTCC1P1Pi.h"
#include "ND280HL2Utils.h"

void pTTCC1P1Pi::DoAnalysis(const TString filelist, const Int_t ntarget, const TString tag, const Int_t krec)
{
    NeutrinoUtils::IniCC1P1Pi();
    Intit(ND280HL2Utils::IniIO(filelist, krac?"default":"truth"));//Sets all the branch pointers and initialises called from header AnaTask1.h
    printf("pTTCC1P1Pi::DoAnalysis ntarget %d\n", ntarget);
    
    TList *lout=NeutrinoUtils::GetHistList(); // Sets the list of callable histgrams
    TTree *tout = NeutrinoUtils::GetTree(); // Sets branch location to TTrees
    
    const Int_t nentries = fChain->GetEntries();//fChain->GetEntriesFast(); - where is this called from check .h file
    Int_t nsel=0;
    Int_t nfail = 0;
    for(Int_t jentry=0; jentry<nentries; jentry++){
        if(jentry%10000==0){
            printf("%d/%d nsel %d nfail %d\n", jentry, nentries,nsel, nfail);
        }
        
        if(!fChain->GetEntry(jentry)){
            printf("AnaTask1::DoAnalysis GetEntry ends at jentry %d\n", jentry);
            break;
        }
        
        //should be similar to numuCCAnalysis
        if(accum_level[0][1]<11){
            nfail++;
            continue;
        }
        
        NeutrinoUtils::FillCount(lout, 0);
        ND280HL2Utils::SaveInfo(nu_truereac, nu_parentpdg, nu_pdg, ntpctracks);
        ND280HL2Utils::SetNeutrinoRec(vertex_pos);
        
        const Int_t nmurec = ND280HL2Utils::SetParticleRec(NeutrinoUtils::fNeutrinoRec, NeutrinoUtils::fMuonRec,   NeutrinoTools::MuonMass(),   selmu_dir, selmu_mom[0], vertex_pos, selmu_endpos, selmu_Chi2[0], selmu_NDOF[0], selmu_ntpcs, selmu_nfgds, selmu_tpc_nhits, selmu_tpc_charge);
        
        const Int_t nprec  = ND280HL2Utils::SetParticleRec(NeutrinoUtils::fNeutrinoRec, NeutrinoUtils::fProtonRec, NeutrinoTools::ProtonMass(), selp_dir,  selp_mom[0],  vertex_pos, selp_endpos,  selp_Chi2[0],  selp_NDOF[0],  selp_ntpcs,  selp_nfgds,  selp_tpc_nhits,  selp_tpc_charge);
        
        const Int_t npirec = ND280HL2Utils::SetParticleRec(NeutrinoUtils::fNeutrinoRec, NeutrinoUtils::fPionRec, NeutrinoTools::PionMass(), selpi_dir, selpi_mom[0], vertex_pos, selpi_endpos, selpi_Chi2[0], selpi_NDOF[0], selpi_ntpcs, selpi_nfgds, selpi_tpc_nhits, selpi_tpc_charge);
        
        NeutrinoUtils::SetMuonNRec(nmurec);
        NeutrinoUtils::SetProtonNRec(nprec);
        

    }
    
    
    
    
    
}
